package 字符串;

import java.lang.reflect.Array;
import java.util.ArrayList;

/**
 * @Author Weton Li
 * @Date 2021/8/29 13:50
 */
public class Bigram字母 {
    public static void main(String[] args) {
        String input = "we will that we will rock you";
        String[] strings = findOcurrences(input, "we", "will");
        for (String s : strings) {
            System.out.print(s+"\t");
        }
    }
    public static String[] findOcurrences(String text, String first, String second) {
        String[] split = text.split(" ");
        int len = split.length;

        ArrayList list = new ArrayList<>();
        for (int i = 0; i < len - 2; i++) {
            if (split[i].equals(first) && split[i + 1].equals(second)) {
                list.add(split[i+2]);
            }
        }
        String[] s = new String[list.size()];
        String[] res = (String[]) list.toArray(s);
        return res;
    }
}
